#pragma once
#include <sys/types.h>
#include <sys/wait.h>

class channel
{
public:
    channel(int wfd, pid_t subprocessid, std::string channelName)
        :_wfd(wfd), _subprocessid(subprocessid), _channelName(channelName)
    {}

    ~channel()
    {}

    const int& GetWfd()
    {return _wfd;}

    const pid_t& GetSubProcessid()
    {return _subprocessid;}

    const std::string& GetChannelName()
    {return _channelName;}

    void Close()
    {close(_wfd);}

    void Wait()
    {
        pid_t rid = waitpid(_subprocessid, nullptr, 0);
        if (rid > 0)
            std::cout << "wait " << _subprocessid << " success" << std::endl;
    }
private:
    int _wfd;
    pid_t _subprocessid;
    std::string _channelName;
};